package com.zjdiepu.www.biz.third.net;

import java.net.SocketTimeoutException;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.zjdiepu.www.base.core.BaseService;
import com.zjdiepu.www.base.enums.type.HttpRequestErrorType;
import com.zjdiepu.www.base.lang.HttpClientException;
import com.zjdiepu.www.common.consts.ThirdService;
import com.zjdiepu.www.commpent.HttpClient;
import com.zjdiepu.www.config.AliServiceProperty;
import com.zjdiepu.www.ibiz.third.IPhoneNumberAddrService;
import com.zjdiepu.www.util.ExceptionHelper;

@Service
public class PhoneNumberAddrServiceImpl extends BaseService implements IPhoneNumberAddrService{

	@Resource
	protected HttpClient httpClient;
	@Resource
	private AliServiceProperty aliServiceProperty;
	
	@Override
	public Map<String,Object> getAddressByPhoneNumber(String phoneCode) throws SocketTimeoutException, HttpClientException {
		Map<String, String> brandParamMap = new HashMap<String, String>();
		brandParamMap.put("num", phoneCode);
		String responseJson = httpClient.get(ThirdService.A_LI_PHONE_NUMBER_ADDRESS, brandParamMap, getAliCommonHeaderMap(aliServiceProperty.getAppCode()));
		logger.debug(responseJson);
		if(StringUtils.isBlank(responseJson)) {
			ExceptionHelper.thow(HttpRequestErrorType.RESPONSE_IS_EMPTY.getCode(), HttpRequestErrorType.RESPONSE_IS_EMPTY.getValue());
		}
		@SuppressWarnings("unchecked")
		Map<String,Object> parseObject = JSON.parseObject(responseJson,Map.class);
		return parseObject;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Map<String, Object> getIdCordInfo(String idNo) throws SocketTimeoutException, HttpClientException {
		Map<String, String> brandParamMap = new HashMap<String, String>();
		brandParamMap.put("cardno", idNo);
		String responseJson = httpClient.get(ThirdService.A_LI_ID_CARDNO, brandParamMap, getAliCommonHeaderMap(aliServiceProperty.getAppCode()));
		logger.debug(responseJson);
		if(StringUtils.isBlank(responseJson)) {
			ExceptionHelper.thow(HttpRequestErrorType.RESPONSE_IS_EMPTY.getCode(), HttpRequestErrorType.RESPONSE_IS_EMPTY.getValue());
		}
		return JSON.parseObject(responseJson,Map.class);
	}
}
